import React, { Component } from 'react'

import { Route, Switch, Redirect } from 'react-router-dom'
import RouterLink from './RouterLink.js'

export default class RouterView extends Component {
  render() {
    let { routes } = this.props;
    return (
      <div>
        <Switch>
          {
            routes.map((item, index) => {
              if (item.from) {
                return <Redirect key={index} from={item.from} exact to={item.to} />
              }
              
              return <Route key={index} path={item.path} render={(router) => {
                // console.log(item.path);
                let Com = item.component;
                if (!item.neednav) {//不需要导航
                  // console.log(item);
                  return <Com routes={item.children} {...router} />
                }
                return <><Com routes={item.children} {...router} />
                  <div className="nav">
                    <RouterLink routes={routes} selfClassName={'appActive'} />
                  </div>
                </>
              }} />
            })
          }
        </Switch>
      </div>
    )
  }
}

